<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="alternate" href="/atom.xml" title="el's blog" type="application/atom+xml">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"right","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="webpack编译你的vue项目生成代码探索">
<meta name="keywords" content="vue,webpack">
<meta property="og:type" content="article">
<meta property="og:title" content="webpack 把你的 vue 项目编译成了什么">
<meta property="og:url" content="http:&#x2F;&#x2F;ever-lose.gitee.io&#x2F;2017&#x2F;12&#x2F;11&#x2F;js-util&#x2F;what-webpack-has-compiled-vue-project&#x2F;index.html">
<meta property="og:site_name" content="el&#39;s blog">
<meta property="og:description" content="webpack编译你的vue项目生成代码探索">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http:&#x2F;&#x2F;7xn4mw.com1.z0.glb.clouddn.com&#x2F;17-12-10&#x2F;52589634.jpg">
<meta property="og:updated_time" content="2019-11-08T06:19:30.918Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;7xn4mw.com1.z0.glb.clouddn.com&#x2F;17-12-10&#x2F;52589634.jpg">

<link rel="canonical" href="http://ever-lose.gitee.io/2017/12/11/js-util/what-webpack-has-compiled-vue-project/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>webpack 把你的 vue 项目编译成了什么 | el's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">el's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">everlose's blog</h1>
      
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://ever-lose.gitee.io/2017/12/11/js-util/what-webpack-has-compiled-vue-project/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpeg">
      <meta itemprop="name" content="everlose">
      <meta itemprop="description" content="focus on Js、CSS、Node...etc">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="el's blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          webpack 把你的 vue 项目编译成了什么
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-12-11 00:09:04" itemprop="dateCreated datePublished" datetime="2017-12-11T00:09:04+08:00">2017-12-11</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-11-08 14:19:30" itemprop="dateModified" datetime="2019-11-08T14:19:30+08:00">2019-11-08</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js-util/" itemprop="url" rel="index">
                    <span itemprop="name">js-util</span>
                  </a>
                </span>
            </span>

          
            <div class="post-description">webpack编译你的vue项目生成代码探索</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>往 main.js 里写入最简单的 vue 项目结构如下</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Vue <span class="keyword">from</span> <span class="string">'vue'</span>;</span><br><span class="line"><span class="keyword">import</span> App <span class="keyword">from</span> <span class="string">'./App.vue'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> Vue(&#123;</span><br><span class="line">    el: <span class="string">'#app'</span>,</span><br><span class="line">    template: <span class="string">'&lt;App/&gt;'</span>,</span><br><span class="line">    components: &#123;</span><br><span class="line">        App</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>App.vue 如下</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h1</span>&gt;</span>&#123;&#123; msg &#125;&#125;<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h2</span>&gt;</span>Essential Links<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://vuejs.org"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>Core Docs<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://forum.vuejs.org"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>Forum<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://chat.vuejs.org"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>Community Chat<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://twitter.com/vuejs"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>Twitter<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h2</span>&gt;</span>Ecosystem<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://router.vuejs.org/"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>vue-router<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://vuex.vuejs.org/"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>vuex<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://vue-loader.vuejs.org/"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>vue-loader<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">li</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"https://github.com/vuejs/awesome-vue"</span> <span class="attr">target</span>=<span class="string">"_blank"</span>&gt;</span>awesome-vue<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span><br><span class="line"><span class="actionscript">    name: <span class="string">'app'</span>,</span></span><br><span class="line">    data() &#123;</span><br><span class="line"><span class="actionscript">        <span class="keyword">return</span> &#123;</span></span><br><span class="line"><span class="actionscript">            msg: <span class="string">'Welcome to Your Vue.js App'</span></span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-id">#app</span> &#123;</span></span><br><span class="line">    font-family: 'Avenir', Helvetica, Arial, sans-serif;</span><br><span class="line">    -webkit-font-smoothing: antialiased;</span><br><span class="line">    -moz-osx-font-smoothing: grayscale;</span><br><span class="line">    text-align: center;</span><br><span class="line"><span class="css">    <span class="selector-tag">color</span>: <span class="selector-id">#2c3e50</span>;</span></span><br><span class="line">    margin-top: 60px;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">h1,</span><br><span class="line">h2 &#123;</span><br><span class="line">    font-weight: normal;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">ul &#123;</span><br><span class="line">    list-style-type: none;</span><br><span class="line">    padding: 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">li &#123;</span><br><span class="line">    display: inline-block;</span><br><span class="line">    margin: 0 10px;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">a &#123;</span><br><span class="line"><span class="css">    <span class="selector-tag">color</span>: <span class="selector-id">#42b983</span>;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>编译生成后得到一个316kb的文件，而在316Kb中包含着什么，我很好奇想探索一番。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">npm run build</span><br><span class="line"></span><br><span class="line">&gt; learning-in-vue@1.0.0 build /Users/everlose/workspace/github/learningInVue</span><br><span class="line">&gt; cross-env NODE_ENV=production webpack --progress --hide-modules</span><br><span class="line"></span><br><span class="line">Hash: 18d868a423b48dc263e9</span><br><span class="line">Version: webpack 3.9.1</span><br><span class="line">Time: 3693ms</span><br><span class="line">       Asset    Size  Chunks                    Chunk Names</span><br><span class="line">    build.js  316 kB       0  [emitted]  [big]  main</span><br><span class="line">build.js.map  399 kB       0  [emitted]         main</span><br></pre></td></tr></table></figure>

<h2 id="代码分解"><a href="#代码分解" class="headerlink" title="代码分解"></a>代码分解</h2><p>按顺序往下解读，<a href="https://github.com/everlose/learningInVue/blob/v0.0.2/dist/build.js" target="_blank" rel="noopener">本篇编译后的代码在这儿</a>，如果只想看结论那么请拉到最后有一张结构梳理图。</p>
<h3 id="webpack-模块机制"><a href="#webpack-模块机制" class="headerlink" title="webpack 模块机制"></a>webpack 模块机制</h3><p>前面70行还是熟悉的 webpack 模块机制的基础代码，关于它的细致解读参见上一篇<a href="https://github.com/everlose/learningInVue/blob/master/docs/webpack%E6%A8%A1%E5%9D%97%E6%9C%BA%E5%88%B6.md" target="_blank" rel="noopener">webpack模块机制</a>，编译后的代码格式如下，并且我做了代码美化，并且插上了中文注释</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/******/</span> (<span class="function"><span class="keyword">function</span>(<span class="params">modules</span>) </span>&#123; <span class="comment">// webpackBootstrap</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// The module cache</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// 缓存模块，所有被加载过的模块都会成为installedModules对象的属性，靠函数__webpack_require__做到。</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="keyword">var</span> installedModules = &#123;&#125;;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// The require function 核心加载方法</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="function"><span class="keyword">function</span> <span class="title">__webpack_require__</span>(<span class="params">moduleId</span>) </span>&#123;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// Check if module is in cache</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// 检查模块是否已在缓存中，是则直接返回缓存中的模块不需要再次加载</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">if</span>(installedModules[moduleId]) &#123;</span><br><span class="line"><span class="comment">/******/</span>             <span class="keyword">return</span> installedModules[moduleId].exports;</span><br><span class="line"><span class="comment">/******/</span>         &#125;</span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// Create a new module (and put it into the cache)</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// 创造一个新模块并放入缓存中，i是模块标识，l意为是否加载此模块完毕，exports是此模块执行后的输出对象</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">var</span> <span class="built_in">module</span> = installedModules[moduleId] = &#123;</span><br><span class="line"><span class="comment">/******/</span>             i: moduleId,</span><br><span class="line"><span class="comment">/******/</span>             l: <span class="literal">false</span>,</span><br><span class="line"><span class="comment">/******/</span>             exports: &#123;&#125;</span><br><span class="line"><span class="comment">/******/</span>         &#125;;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// Execute the module function</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// 传入参数并执行模块函数</span></span><br><span class="line"><span class="comment">/******/</span>         modules[moduleId].call(<span class="built_in">module</span>.exports, <span class="built_in">module</span>, <span class="built_in">module</span>.exports, __webpack_require__);</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// Flag the module as loaded 标为true代表模块执行完成。</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="built_in">module</span>.l = <span class="literal">true</span>;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// Return the exports of the module 返回此模块输出的对象</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">return</span> <span class="built_in">module</span>.exports;</span><br><span class="line"><span class="comment">/******/</span>     &#125;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// expose the modules object (__webpack_modules__)</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// webpack 私有变量，保存传入的modules，即所有的模块组成的数组</span></span><br><span class="line"><span class="comment">/******/</span>     __webpack_require__.m = modules;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// expose the module cache</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// 保存缓存中的模块数组</span></span><br><span class="line"><span class="comment">/******/</span>     __webpack_require__.c = installedModules;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// define getter function for harmony exports</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// 为 es6 exports 定义 getter</span></span><br><span class="line"><span class="comment">/******/</span>     __webpack_require__.d = <span class="function"><span class="keyword">function</span>(<span class="params">exports, name, getter</span>) </span>&#123;</span><br><span class="line"><span class="comment">/******/</span>         <span class="comment">// 如果 exports 输出的对象本身不包含 name 属性时，定义一个。</span></span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">if</span>(!__webpack_require__.o(exports, name)) &#123;</span><br><span class="line"><span class="comment">/******/</span>             <span class="built_in">Object</span>.defineProperty(exports, name, &#123;</span><br><span class="line"><span class="comment">/******/</span>                 configurable: <span class="literal">false</span>,</span><br><span class="line"><span class="comment">/******/</span>                 enumerable: <span class="literal">true</span>,</span><br><span class="line"><span class="comment">/******/</span>                 <span class="keyword">get</span>: getter</span><br><span class="line">/******/             &#125;);</span><br><span class="line">/******/         &#125;</span><br><span class="line">/******/     &#125;;</span><br><span class="line">/******/</span><br><span class="line">/******/     // getDefaultExport function for compatibility with non-harmony modules</span><br><span class="line">/******/     // 解决 ES module 和 Common js module 的冲突，ES 则返回 module['default']</span><br><span class="line">/******/     __webpack_require__.n = function(module) &#123;</span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">var</span> getter = <span class="built_in">module</span> &amp;&amp; <span class="built_in">module</span>.__esModule ?</span><br><span class="line"><span class="comment">/******/</span>             <span class="function"><span class="keyword">function</span> <span class="title">getDefault</span>(<span class="params"></span>) </span>&#123; <span class="keyword">return</span> <span class="built_in">module</span>[<span class="string">'default'</span>]; &#125; :</span><br><span class="line"><span class="comment">/******/</span>             <span class="function"><span class="keyword">function</span> <span class="title">getModuleExports</span>(<span class="params"></span>) </span>&#123; <span class="keyword">return</span> <span class="built_in">module</span>; &#125;;</span><br><span class="line"><span class="comment">/******/</span>         __webpack_require__.d(getter, <span class="string">'a'</span>, getter);</span><br><span class="line"><span class="comment">/******/</span>         <span class="keyword">return</span> getter;</span><br><span class="line"><span class="comment">/******/</span>     &#125;;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// Object.prototype.hasOwnProperty.call</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// 工具方法，判断是否object有property属性。</span></span><br><span class="line"><span class="comment">/******/</span>     __webpack_require__.o = <span class="function"><span class="keyword">function</span>(<span class="params">object, property</span>) </span>&#123; <span class="keyword">return</span> <span class="built_in">Object</span>.prototype.hasOwnProperty.call(object, property); &#125;;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// __webpack_public_path__</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// 大概和 webpack.config.js 的 output 有关吧，webpack 的公共路径</span></span><br><span class="line"><span class="comment">/******/</span>     __webpack_require__.p = <span class="string">"/dist/"</span>;</span><br><span class="line"><span class="comment">/******/</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="comment">// Load entry module and return exports 执行第一个依赖模块并且返回它输出。</span></span><br><span class="line"><span class="comment">/******/</span>     <span class="keyword">return</span> __webpack_require__(__webpack_require__.s = <span class="number">0</span>);</span><br><span class="line"><span class="comment">/******/</span> &#125;)</span><br></pre></td></tr></table></figure>

<h3 id="0号模块"><a href="#0号模块" class="headerlink" title="0号模块"></a>0号模块</h3><p>导出一个全局变量，在web端就是指代window</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 0 */</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> g;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// This works in non-strict mode</span></span><br><span class="line">    g = (<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">    &#125;)();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">// This works if eval is allowed (see CSP)</span></span><br><span class="line">        g = g || <span class="built_in">Function</span>(<span class="string">"return this"</span>)() || (<span class="number">1</span>, <span class="built_in">eval</span>)(<span class="string">"this"</span>);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (e) &#123;</span><br><span class="line">        <span class="comment">// This works if the window reference is available</span></span><br><span class="line">        <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="built_in">window</span> === <span class="string">"object"</span>)</span><br><span class="line">            g = <span class="built_in">window</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// g can still be undefined, but nothing to do about it...</span></span><br><span class="line">    <span class="comment">// We return undefined, instead of nothing here, so it's</span></span><br><span class="line">    <span class="comment">// easier to handle this case. if(!global) &#123; ...&#125;</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">module</span>.exports = g;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>

<h3 id="1号模块"><a href="#1号模块" class="headerlink" title="1号模块"></a>1号模块</h3><p>实际上做的事情很明显，就是导出了 main.js 的代码，一个vue实例对象</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 1 */</span></span><br><span class="line"><span class="comment">/***/</span> (<span class="function"><span class="keyword">function</span>(<span class="params">module, __webpack_exports__, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">"use strict"</span>;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(__webpack_exports__, <span class="string">"__esModule"</span>, &#123; <span class="attr">value</span>: <span class="literal">true</span> &#125;);</span><br><span class="line"><span class="comment">/* harmony import */</span> <span class="keyword">var</span> __WEBPACK_IMPORTED_MODULE_0_vue__ = __webpack_require__(<span class="number">2</span>);</span><br><span class="line"><span class="comment">/* harmony import */</span> <span class="keyword">var</span> __WEBPACK_IMPORTED_MODULE_1__App_vue__ = __webpack_require__(<span class="number">6</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 从2号模块导出的一个叫a的变量，就是Vue对象本身</span></span><br><span class="line"><span class="keyword">new</span> __WEBPACK_IMPORTED_MODULE_0_vue__[<span class="string">"a"</span> <span class="comment">/* default */</span>](&#123;</span><br><span class="line">    el: <span class="string">'#app'</span>,</span><br><span class="line">    template: <span class="string">'&lt;App/&gt;'</span>,</span><br><span class="line">    components: &#123;</span><br><span class="line">        App: __WEBPACK_IMPORTED_MODULE_1__App_vue__[<span class="string">"a"</span> <span class="comment">/* default */</span>]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">/***/</span> &#125;)</span><br></pre></td></tr></table></figure>

<h3 id="2号模块"><a href="#2号模块" class="headerlink" title="2号模块"></a>2号模块</h3><p>即是 Vue 源码本身，从114行一直到了10818行，一共是10705行代码，啧啧啧</p>
<p>webpack 有所配置，所以导出的 Vue 实际上是 vue/dist/vue.esm.js 的完整编译版本。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 2 */</span></span><br><span class="line"><span class="comment">/***/</span> (<span class="function"><span class="keyword">function</span> (<span class="params">module, __webpack_exports__, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">"use strict"</span>;</span><br><span class="line"><span class="comment">/*!</span></span><br><span class="line"><span class="comment"> * Vue.js v2.5.9</span></span><br><span class="line"><span class="comment"> * (c) 2014-2017 Evan You</span></span><br><span class="line"><span class="comment"> * Released under the MIT License.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 作用域指向__webpack_exports__，并把__webpack_require__(0)作为global，实际上就是window</span></span><br><span class="line"><span class="comment">// __webpack_require__(3).setImmediate)作为setsetImmediate参数传入函数</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">global, setImmediate</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 省略近1w行的代码，关于vue原本本身的解读以后再做......</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 最终 export 出来一个叫 Vue$3的对象</span></span><br><span class="line">    <span class="comment">/* harmony default export */</span></span><br><span class="line">    __webpack_exports__[<span class="string">"a"</span>] = (Vue$<span class="number">3</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* WEBPACK VAR INJECTION */</span></span><br><span class="line">&#125;.call(__webpack_exports__, __webpack_require__(<span class="number">0</span>), __webpack_require__(<span class="number">3</span>).setImmediate))</span><br><span class="line"></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>

<h3 id="3，4，5号模块"><a href="#3，4，5号模块" class="headerlink" title="3，4，5号模块"></a>3，4，5号模块</h3><p>都和 node_modules/setimmediate 有关，由于 vue 的 DOM 异步更新机制使用到了它，所以被引入。</p>
<p>这里也不做详解，只给出结构。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 3 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 省略代码...</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// setimmediate attaches itself to the global object</span></span><br><span class="line">    __webpack_require__(<span class="number">4</span>);</span><br><span class="line">    exports.setImmediate = setImmediate;</span><br><span class="line">    exports.clearImmediate = clearImmediate;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 4 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* WEBPACK VAR INJECTION */</span></span><br><span class="line">    (<span class="function"><span class="keyword">function</span> (<span class="params">global, process</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 省略代码...</span></span><br><span class="line">    &#125;.call(exports, __webpack_require__(<span class="number">0</span>), __webpack_require__(<span class="number">5</span>)))</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 5 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// shim for using process in browser</span></span><br><span class="line">    <span class="keyword">var</span> process = <span class="built_in">module</span>.exports = &#123;&#125;;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 省略代码...</span></span><br><span class="line"></span><br><span class="line">    process.cwd = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">'/'</span></span><br><span class="line">    &#125;;</span><br><span class="line">    process.chdir = <span class="function"><span class="keyword">function</span> (<span class="params">dir</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> <span class="built_in">Error</span>(<span class="string">'process.chdir is not supported'</span>);</span><br><span class="line">    &#125;;</span><br><span class="line">    process.umask = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>

<h3 id="6号模块"><a href="#6号模块" class="headerlink" title="6号模块"></a>6号模块</h3><p>和 App.vue 的解析有关，把 App.vue 中的 template 和 script 编译为一个 vue components，并把 style 标签内的样式插入到DOM中。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 6 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, __webpack_exports__, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">    "use strict"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 返回具体 App.vue 中 的script 中的代码</span></span><br><span class="line">    <span class="keyword">var</span> __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_App_vue__ = __webpack_require__(<span class="number">13</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 把App.vue 的 template 解析为一堆 vue render 函数。</span></span><br><span class="line">    <span class="keyword">var</span> __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_66ce2159_hasScoped_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_App_vue__ = __webpack_require__(<span class="number">14</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 注入vue文件里写入的css函数</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">injectStyle</span>(<span class="params">ssrContext</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 由此可知7号模块是编译并插入vue中的css到DOM上的</span></span><br><span class="line">        __webpack_require__(<span class="number">7</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 12号模块用于输出components渲染函数</span></span><br><span class="line">    <span class="keyword">var</span> normalizeComponent = __webpack_require__(<span class="number">12</span>)</span><br><span class="line">    <span class="comment">/* script */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* template */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* template functional */</span></span><br><span class="line">    <span class="keyword">var</span> __vue_template_functional__ = <span class="literal">false</span></span><br><span class="line">    <span class="comment">/* styles */</span></span><br><span class="line">    <span class="keyword">var</span> __vue_styles__ = injectStyle</span><br><span class="line">    <span class="comment">/* scopeId */</span></span><br><span class="line">    <span class="keyword">var</span> __vue_scopeId__ = <span class="literal">null</span></span><br><span class="line">    <span class="comment">/* moduleIdentifier (server only) */</span></span><br><span class="line">    <span class="keyword">var</span> __vue_module_identifier__ = <span class="literal">null</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 编译模块，混杂template和script。</span></span><br><span class="line">    <span class="keyword">var</span> Component = normalizeComponent(</span><br><span class="line">        __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_App_vue__[<span class="string">"a"</span> <span class="comment">/* default */</span> ],</span><br><span class="line">        __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_66ce2159_hasScoped_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_App_vue__[<span class="string">"a"</span> <span class="comment">/* default */</span> ],</span><br><span class="line">        __vue_template_functional__,</span><br><span class="line">        __vue_styles__,</span><br><span class="line">        __vue_scopeId__,</span><br><span class="line">        __vue_module_identifier__</span><br><span class="line">    )</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* harmony default export */</span></span><br><span class="line">    __webpack_exports__[<span class="string">"a"</span>] = (Component.exports);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>

<h3 id="7、8、9、10、11"><a href="#7、8、9、10、11" class="headerlink" title="7、8、9、10、11"></a>7、8、9、10、11</h3><p>都和样式有关，简言之就是7号模块加载8号模块获取css代码作为参数，并作为参数传入10号模块进行插入</p>
<p>太长也只大意上列出结构</p>
<ul>
<li>7号模块由 style-loader 带入，把所有的css插入到 style 标签里</li>
<li>8号模块加载具体的css代码，</li>
<li>9号模块由css-loader代入，用于做css的sourceMap</li>
<li>10号模块返回具体插入动作函数，供7号模块调用</li>
<li>11号模块把所有的样式组成的数组转为字符串，给10号模块做插入。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 7 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// style-loader: Adds some css to the DOM by adding a &lt;style&gt; tag</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// load the styles</span></span><br><span class="line">    <span class="keyword">var</span> content = __webpack_require__(<span class="number">8</span>);</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> content === <span class="string">'string'</span>) content = [</span><br><span class="line">        [<span class="built_in">module</span>.i, content, <span class="string">''</span>]</span><br><span class="line">    ];</span><br><span class="line">    <span class="keyword">if</span> (content.locals) <span class="built_in">module</span>.exports = content.locals;</span><br><span class="line">    <span class="comment">// add the styles to the DOM</span></span><br><span class="line">    <span class="keyword">var</span> update = __webpack_require__(<span class="number">10</span>)(<span class="string">"15459d21"</span>, content, <span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 8 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// css-loader 用于做css的sourceMap</span></span><br><span class="line">    exports = <span class="built_in">module</span>.exports = __webpack_require__(<span class="number">9</span>)(<span class="literal">undefined</span>);</span><br><span class="line">    <span class="comment">// imports</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">// module</span></span><br><span class="line">    <span class="comment">// 这就是 App.vue 文件中 style 里的的 css</span></span><br><span class="line">    exports.push([<span class="built_in">module</span>.i, <span class="string">"#app&#123;font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50;margin-top:60px&#125;h1,h2&#123;font-weight:400&#125;ul&#123;list-style-type:none;padding:0&#125;li&#123;display:inline-block;margin:0 10px&#125;a&#123;color:#42b983&#125;"</span>, <span class="string">""</span>]);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// exports</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 9 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// css base code, injected by the css-loader</span></span><br><span class="line">    <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">useSourceMap</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 省略代码...</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 10 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports, __webpack_require__</span>) </span>&#123;</span><br><span class="line">    <span class="comment">/*</span></span><br><span class="line"><span class="comment">        MIT License http://www.opensource.org/licenses/mit-license.php</span></span><br><span class="line"><span class="comment">        Author Tobias Koppers @sokra</span></span><br><span class="line"><span class="comment">        Modified by Evan You @yyx990803</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// ...太长只贴了关键步骤，总之关键的函数就是这些</span></span><br><span class="line">    <span class="keyword">var</span> hasDocument = <span class="keyword">typeof</span> <span class="built_in">document</span> !== <span class="string">'undefined'</span></span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">    <span class="keyword">var</span> listToStyles = __webpack_require__(<span class="number">11</span>)</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">    <span class="keyword">var</span> head = hasDocument &amp;&amp; (<span class="built_in">document</span>.head || <span class="built_in">document</span>.getElementsByTagName(<span class="string">'head'</span>)[<span class="number">0</span>])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">    <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> (<span class="params">parentId, list, _isProduction</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">        <span class="keyword">var</span> styles = listToStyles(parentId, list)</span><br><span class="line">        addStylesToDom(styles)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> <span class="title">update</span> (<span class="params">newList</span>) </span>&#123;</span><br><span class="line">            <span class="comment">// ...</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">addStylesToDom</span> (<span class="params">styles <span class="regexp">/* Array&lt;StyleObject&gt; */</span></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; styles.length; i++) &#123;</span><br><span class="line">            <span class="comment">// ...</span></span><br><span class="line">            domStyle.parts.push(addStyle(item.parts[j]))</span><br><span class="line">            <span class="comment">// ....</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 总之先调用了addStylesToDom，接着是addStyle，再是createStyleElement插入样式到head中。</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">createStyleElement</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> styleElement = <span class="built_in">document</span>.createElement(<span class="string">'style'</span>)</span><br><span class="line">    styleElement.type = <span class="string">'text/css'</span></span><br><span class="line">    head.appendChild(styleElement)</span><br><span class="line">    <span class="keyword">return</span> styleElement</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">addStyle</span> (<span class="params">obj <span class="regexp">/* StyleObjectPart */</span></span>) </span>&#123;</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">        styleElement = createStyleElement()</span><br><span class="line">        <span class="comment">// ...</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 11 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Translates the list format produced by css-loader into something</span></span><br><span class="line"><span class="comment">     * easier to manipulate.</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> <span class="title">listToStyles</span>(<span class="params">parentId, list</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> styles = []</span><br><span class="line">        <span class="keyword">var</span> newStyles = &#123;&#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; list.length; i++) &#123;</span><br><span class="line">            <span class="keyword">var</span> item = list[i]</span><br><span class="line">            <span class="keyword">var</span> id = item[<span class="number">0</span>]</span><br><span class="line">            <span class="keyword">var</span> css = item[<span class="number">1</span>]</span><br><span class="line">            <span class="keyword">var</span> media = item[<span class="number">2</span>]</span><br><span class="line">            <span class="keyword">var</span> sourceMap = item[<span class="number">3</span>]</span><br><span class="line">            <span class="keyword">var</span> part = &#123;</span><br><span class="line">                id: parentId + <span class="string">':'</span> + i,</span><br><span class="line">                css: css,</span><br><span class="line">                media: media,</span><br><span class="line">                sourceMap: sourceMap</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (!newStyles[id]) &#123;</span><br><span class="line">                styles.push(newStyles[id] = &#123;</span><br><span class="line">                    id: id,</span><br><span class="line">                    parts: [part]</span><br><span class="line">                &#125;)</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                newStyles[id].parts.push(part)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> styles</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>

<h3 id="12、13、14号模块"><a href="#12、13、14号模块" class="headerlink" title="12、13、14号模块"></a>12、13、14号模块</h3><p>12号做 .vue 文件中的 template 和 script 解析并供6号输出，最终返回了一个 vue components 对象，在浏览器控制台打印如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">Object</span><br><span class="line">    beforeCreate: [ƒ]</span><br><span class="line">    data: ƒ data()</span><br><span class="line">    inject: &#123;&#125;</span><br><span class="line">    name: &quot;app&quot;</span><br><span class="line">    render: ƒ ()</span><br><span class="line">    staticRenderFns: (2) [ƒ, ƒ, cached: Array(2)]</span><br><span class="line">    _Ctor: &#123;0: ƒ&#125;</span><br><span class="line">    _compiled: true</span><br><span class="line">    __proto__: Object</span><br></pre></td></tr></table></figure>

<p>而13号模块返回具体 script 中的代码，而14号模块则是把 template 解析为一堆 vue render 函数。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 12 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, exports</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* globals __VUE_SSR_CONTEXT__ */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// IMPORTANT: Do NOT use ES2015 features in this file.</span></span><br><span class="line">    <span class="comment">// This module is a runtime utility for cleaner component module output and will</span></span><br><span class="line">    <span class="comment">// be included in the final webpack user bundle.</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">module</span>.exports = <span class="function"><span class="keyword">function</span> <span class="title">normalizeComponent</span>(<span class="params"></span></span></span><br><span class="line"><span class="function"><span class="params">        rawScriptExports,</span></span></span><br><span class="line"><span class="function"><span class="params">        compiledTemplate,</span></span></span><br><span class="line"><span class="function"><span class="params">        functionalTemplate,</span></span></span><br><span class="line"><span class="function"><span class="params">        injectStyles,</span></span></span><br><span class="line"><span class="function"><span class="params">        scopeId,</span></span></span><br><span class="line"><span class="function"><span class="params">        moduleIdentifier <span class="regexp">/* server only */</span></span></span></span><br><span class="line"><span class="function"><span class="params">    </span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> esModule</span><br><span class="line">        <span class="keyword">var</span> scriptExports = rawScriptExports = rawScriptExports || &#123;&#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// ES6 modules interop</span></span><br><span class="line">        <span class="keyword">var</span> type = <span class="keyword">typeof</span> rawScriptExports.default</span><br><span class="line">        <span class="keyword">if</span> (type === <span class="string">'object'</span> || type === <span class="string">'function'</span>) &#123;</span><br><span class="line">            esModule = rawScriptExports</span><br><span class="line">            scriptExports = rawScriptExports.default</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// Vue.extend constructor export interop</span></span><br><span class="line">        <span class="keyword">var</span> options = <span class="keyword">typeof</span> scriptExports === <span class="string">'function'</span> ?</span><br><span class="line">            scriptExports.options :</span><br><span class="line">            scriptExports</span><br><span class="line"></span><br><span class="line">        <span class="comment">// render functions</span></span><br><span class="line">        <span class="keyword">if</span> (compiledTemplate) &#123;</span><br><span class="line">            options.render = compiledTemplate.render</span><br><span class="line">            options.staticRenderFns = compiledTemplate.staticRenderFns</span><br><span class="line">            options._compiled = <span class="literal">true</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// functional template</span></span><br><span class="line">        <span class="keyword">if</span> (functionalTemplate) &#123;</span><br><span class="line">            options.functional = <span class="literal">true</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// scopedId</span></span><br><span class="line">        <span class="keyword">if</span> (scopeId) &#123;</span><br><span class="line">            options._scopeId = scopeId</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">var</span> hook</span><br><span class="line">        <span class="keyword">if</span> (moduleIdentifier) &#123; <span class="comment">// server build</span></span><br><span class="line">            hook = <span class="function"><span class="keyword">function</span> (<span class="params">context</span>) </span>&#123;</span><br><span class="line">                <span class="comment">// 2.3 injection</span></span><br><span class="line">                context =</span><br><span class="line">                    context || <span class="comment">// cached call</span></span><br><span class="line">                    (<span class="keyword">this</span>.$vnode &amp;&amp; <span class="keyword">this</span>.$vnode.ssrContext) || <span class="comment">// stateful</span></span><br><span class="line">                    (<span class="keyword">this</span>.parent &amp;&amp; <span class="keyword">this</span>.parent.$vnode &amp;&amp; <span class="keyword">this</span>.parent.$vnode.ssrContext) <span class="comment">// functional</span></span><br><span class="line">                <span class="comment">// 2.2 with runInNewContext: true</span></span><br><span class="line">                <span class="keyword">if</span> (!context &amp;&amp; <span class="keyword">typeof</span> __VUE_SSR_CONTEXT__ !== <span class="string">'undefined'</span>) &#123;</span><br><span class="line">                    context = __VUE_SSR_CONTEXT__</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">// inject component styles</span></span><br><span class="line">                <span class="keyword">if</span> (injectStyles) &#123;</span><br><span class="line">                    injectStyles.call(<span class="keyword">this</span>, context)</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="comment">// register component module identifier for async chunk inferrence</span></span><br><span class="line">                <span class="keyword">if</span> (context &amp;&amp; context._registeredComponents) &#123;</span><br><span class="line">                    context._registeredComponents.add(moduleIdentifier)</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="comment">// used by ssr in case component is cached and beforeCreate</span></span><br><span class="line">            <span class="comment">// never gets called</span></span><br><span class="line">            options._ssrRegister = hook</span><br><span class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (injectStyles) &#123;</span><br><span class="line">            hook = injectStyles</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (hook) &#123;</span><br><span class="line">            <span class="keyword">var</span> functional = options.functional</span><br><span class="line">            <span class="keyword">var</span> existing = functional ?</span><br><span class="line">                options.render :</span><br><span class="line">                options.beforeCreate</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (!functional) &#123;</span><br><span class="line">                <span class="comment">// inject component registration as beforeCreate hook</span></span><br><span class="line">                options.beforeCreate = existing ?</span><br><span class="line">                    [].concat(existing, hook) :</span><br><span class="line">                    [hook]</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// for template-only hot-reload because in that case the render fn doesn't</span></span><br><span class="line">                <span class="comment">// go through the normalizer</span></span><br><span class="line">                options._injectStyles = hook</span><br><span class="line">                <span class="comment">// register for functioal component in vue file</span></span><br><span class="line">                options.render = <span class="function"><span class="keyword">function</span> <span class="title">renderWithStyleInjection</span>(<span class="params">h, context</span>) </span>&#123;</span><br><span class="line">                    hook.call(context)</span><br><span class="line">                    <span class="keyword">return</span> existing(h, context)</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            esModule: esModule,</span><br><span class="line">            exports: scriptExports,</span><br><span class="line">            options: options</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 13 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, __webpack_exports__, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">    "use strict"</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* harmony default export */</span></span><br><span class="line">    <span class="comment">// 这就是 App.vue 中 script 的部分</span></span><br><span class="line">    __webpack_exports__[<span class="string">"a"</span>] = (&#123;</span><br><span class="line">        name: <span class="string">'app'</span>,</span><br><span class="line">        data: <span class="function"><span class="keyword">function</span> <span class="title">data</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> &#123;</span><br><span class="line">                msg: <span class="string">'Welcome to Your Vue.js App'</span></span><br><span class="line">            &#125;;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;),</span><br><span class="line"><span class="comment">/* 14 */</span></span><br><span class="line"><span class="comment">/***/</span></span><br><span class="line">(<span class="function"><span class="keyword">function</span> (<span class="params">module, __webpack_exports__, __webpack_require__</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line"><span class="meta">    "use strict"</span>;</span><br><span class="line">    <span class="comment">// 把template 解析为一堆 render 函数，扔给vue处理最终编译成Vnode节点在渲染成DOM输出到视图</span></span><br><span class="line">    <span class="keyword">var</span> render = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> _vm = <span class="keyword">this</span>;</span><br><span class="line">        <span class="keyword">var</span> _h = _vm.$createElement;</span><br><span class="line">        <span class="keyword">var</span> _c = _vm._self._c || _h;</span><br><span class="line">        <span class="keyword">return</span> _c(<span class="string">'div'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"id"</span>: <span class="string">"app"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_c(<span class="string">'h1'</span>, [_vm._v(_vm._s(_vm.msg))]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'h2'</span>, [_vm._v(<span class="string">"Essential Links"</span>)]), _vm._v(<span class="string">" "</span>), _vm._m(<span class="number">0</span>, <span class="literal">false</span>, <span class="literal">false</span>), _vm._v(<span class="string">" "</span>), _c(<span class="string">'h2'</span>, [_vm._v(<span class="string">"Ecosystem"</span>)]), _vm._v(<span class="string">" "</span>), _vm._m(<span class="number">1</span>, <span class="literal">false</span>, <span class="literal">false</span>)])</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">var</span> staticRenderFns = [<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> _vm = <span class="keyword">this</span>;</span><br><span class="line">        <span class="keyword">var</span> _h = _vm.$createElement;</span><br><span class="line">        <span class="keyword">var</span> _c = _vm._self._c || _h;</span><br><span class="line">        <span class="keyword">return</span> _c(<span class="string">'ul'</span>, [_c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"https://vuejs.org"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"Core Docs"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"https://forum.vuejs.org"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"Forum"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"https://chat.vuejs.org"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"Community Chat"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"https://twitter.com/vuejs"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"Twitter"</span>)])])])</span><br><span class="line">    &#125;, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> _vm = <span class="keyword">this</span>;</span><br><span class="line">        <span class="keyword">var</span> _h = _vm.$createElement;</span><br><span class="line">        <span class="keyword">var</span> _c = _vm._self._c || _h;</span><br><span class="line">        <span class="keyword">return</span> _c(<span class="string">'ul'</span>, [_c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"http://router.vuejs.org/"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"vue-router"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"http://vuex.vuejs.org/"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"vuex"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"http://vue-loader.vuejs.org/"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"vue-loader"</span>)])]), _vm._v(<span class="string">" "</span>), _c(<span class="string">'li'</span>, [_c(<span class="string">'a'</span>, &#123;</span><br><span class="line">            attrs: &#123;</span><br><span class="line">                <span class="string">"href"</span>: <span class="string">"https://github.com/vuejs/awesome-vue"</span>,</span><br><span class="line">                <span class="string">"target"</span>: <span class="string">"_blank"</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;, [_vm._v(<span class="string">"awesome-vue"</span>)])])])</span><br><span class="line">    &#125;]</span><br><span class="line">    <span class="keyword">var</span> esExports = &#123;</span><br><span class="line">        render: render,</span><br><span class="line">        staticRenderFns: staticRenderFns</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">/* harmony default export */</span></span><br><span class="line">    __webpack_exports__[<span class="string">"a"</span>] = (esExports);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/***/</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>结构梳理，一图胜千言，并且有关于<a href="http://naotu.baidu.com/file/89611b9bc6cd0ac214a98abbd5062ade?token=60ef60d5ed3a60cf" target="_blank" rel="noopener">此图的附注请自行点击参考</a></p>
<p><img src="http://7xn4mw.com1.z0.glb.clouddn.com/17-12-10/52589634.jpg" alt=""></p>
<p>上一篇：<a href="https://github.com/everlose/learningInVue/blob/master/docs/webpack%E6%A8%A1%E5%9D%97%E6%9C%BA%E5%88%B6.md" target="_blank" rel="noopener">webpack模块机制</a></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/vue/" rel="tag"># vue</a>
              <a href="/tags/webpack/" rel="tag"># webpack</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
                <a href="/2017/12/11/js-util/webpack-core/" rel="next" title="webpack 打包机制">
                  <i class="fa fa-chevron-left"></i> webpack 打包机制
                </a>
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
                <a href="/2017/12/16/javascript/ES6-standard-LogicalANDExpression/" rel="prev" title="ES6标准之逻辑与的规则">
                  ES6标准之逻辑与的规则 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="gitalk-container"></div>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#代码分解"><span class="nav-number">2.</span> <span class="nav-text">代码分解</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#webpack-模块机制"><span class="nav-number">2.1.</span> <span class="nav-text">webpack 模块机制</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#0号模块"><span class="nav-number">2.2.</span> <span class="nav-text">0号模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1号模块"><span class="nav-number">2.3.</span> <span class="nav-text">1号模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2号模块"><span class="nav-number">2.4.</span> <span class="nav-text">2号模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3，4，5号模块"><span class="nav-number">2.5.</span> <span class="nav-text">3，4，5号模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6号模块"><span class="nav-number">2.6.</span> <span class="nav-text">6号模块</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7、8、9、10、11"><span class="nav-number">2.7.</span> <span class="nav-text">7、8、9、10、11</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12、13、14号模块"><span class="nav-number">2.8.</span> <span class="nav-text">12、13、14号模块</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">3.</span> <span class="nav-text">总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="site-author-image" itemprop="image" alt="everlose"
    src="/images/avatar.jpeg">
  <p class="site-author-name" itemprop="name">everlose</p>
  <div class="site-description" itemprop="description">focus on Js、CSS、Node...etc</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">97</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">12</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="feed-link motion-element">
    <a href="/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/everlose" title="GitHub &amp;rarr; https:&#x2F;&#x2F;github.com&#x2F;everlose" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/mailto:ever-lose@foxmail.com" title="E-Mail &amp;rarr; mailto:ever-lose@foxmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">everlose</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.0.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.5.0
  </div>

        












        
      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/muse.js"></script>
<script src="/js/next-boot.js"></script>



  




  <script src="/js/local-search.js"></script>













  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID: '48fe7d5cb2ac7e2c7fbf',
      clientSecret: '8f67b574218201d3b3ec6efe69276902e711e655',
      repo: 'everlose-blog',
      owner: 'everlose',
      admin: [''],
      id: 'fce8d56782c34edb8add14a1cc215bfe',
        language: 'zh-CN',
      distractionFreeMode: 'true'
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
</script>

</body>
</html>
